using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace WiiMouseLib
{
    public partial class frmSettings : Form
    {
        public frmSettings()
        {
            InitializeComponent();
        }

        private void frmSettings_Load(object sender, EventArgs e)
        {
            bindingSource1.DataSource = wiiMouse1;
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                wiiMouse1.connect(this);
                btnConnect.Hide();
                notifyIcon1.Visible = true;
                Hide();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("There was an error connecting to the Wiimote: " + ex.ToString(), "Error Connecting to Wiimote", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            notifyIcon1.Visible = false;
        }

        private bool reallyExit = false;

        private void reallyClose()
        {
            reallyExit = true;
            notifyIcon1.Visible = false;
            Close();
        }

        private void frmSettings_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!reallyExit)
            {
                e.Cancel = true;
                notifyIcon1.Visible = true;
                Hide();
            }
        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            reallyClose();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            reallyClose();
        }
    }
}